<?

Q::register($customer, 'customer');
$countries = Country::find()->getAll();
Q::register($countries, 'countries');

$mailPlans = Mail_Plan::find()->getAll();

function renderCountryId($id)
{
    $countries = Q::registry('countries');

    $ret = '<select id="country_id" name="country_id"><option>--请选择--</option>';
    foreach ($countries as $c) {
        $ret .= '<option value="' . $c->id() . '" utc_offset="' . $c->utc_offset . '"';
        if ($c->id() == $id) {
            $ret .= ' selected="selected"';
        }
        $ret .= '>' . $c->name . ' ' . $c->chinese_name . '</option>';
    }

    $ret .= '</select>';
    return $ret;
}

function renderUtcOffset($offset)
{
    $countries = Q::registry('countries');
    $countries = $countries->toHashmap('country_id');
    $customer = Q::registry('customer');

    if (isset($countries[$customer->country_id]->utc_offset)) {
        $offsets = Q::normalize($countries[$customer->country_id]->utc_offset);
    } else {
        $offsets = array('');
    }

    if (count($offsets) > 1) {
        return Q::control('dropdownlist', 'utc_offset', array('items' => $offsets, 'captions' => $offsets, 'value' => $offset));
    } else {
        return '<input readonly name="utc_offset" id="utc_offset" value="' . $offset . '" />';
    }
}

function renderAddressMailStatus($status)
{
    if ($status == Mail_Address_Plan::PLAN_STATUS_PAUSED) {
        return '已暂停';
    }

    if ($status == Mail_Address_Plan::PLAN_STATUS_PROCESSING) {
        return '正常运行';
    }
}

?>

<?php $this->_extends('_layouts/default_layout'); ?>

<?php $this->_block('title'); ?><?= $pageTitle ?><?php $this->_endblock(); ?>

<?php $this->_block('js'); ?>
<link rel="stylesheet" type="text/css" href="<?=$_BASE_DIR?>js/jquerytools/1.2.5/dateinput.css"/>
<link rel="stylesheet" type="text/css" href="<?=$_BASE_DIR?>js/jquerytools/1.2.5/tabs.css"/>
<script src="<?=$_BASE_DIR?>js/jquerytools/1.2.5/jquery.tools.min.js"></script>
<script type="text/javascript">

function d(o, mode) {
    if (typeof o == 'object') {
        var str = '';
        for (var p in o) {
            if (mode != 'all' && typeof o[p] == 'function') continue;
            str += p + ": " + o[p] + '\r\n';
        }
        alert(str);
    } else {
        alert(o);
    }
}

var mailAddresses = [];

$(function() {
    var
            $country_id = $('#country_id'),
            $customer_id = $('#customer_id'),
            $addProfessionBtn = $("#addProfessionBtn"),
            $addProfessionForm = $('#addProfessionForm'),
            $addProfessionResult = $('#addProfessionResult'),
            $newProfession = $('#newProfession'),
            $profession_id = $('#profession_id'),

            $addMailAddressBtn = $("#addMailAddressBtn"),
            $addMailAddressForm = $('#addMailAddressForm'),
            $addMailAddressResult = $('#addMailAddressResult'),
            $newMailAddress = $('#newMailAddress'),
            $mailAddressTable = $('#mailAddressTable'),

            $mainForm = $('#mainForm'),

            $submitBaseData = $('#submitBaseData'),
            $showMailPlanPanelTrg = $('#showMailPlanPanelTrg'),
            $mailPlanTable = $('#mailPlanTable'),
            $mailAddressPlanTable = $('#mailAddressPlanTable'),
            $mailPlanCfgPanel = $('#mailPlanCfgPanel'),
            $submitMailPlanCfg = $('#submitMailPlanCfg'),
            $bindMailPlanTrg = $('#bindMailPlanTrg'),
            $waitingListTable = $('#waitingListTable'),
            $showMoreWaitingList = $('#showMoreWaitingList');
    $refreshWaitingList = $('#refreshWaitingList');


    function get_customer_id() {
        if ($customer_id.val() == '') $mainForm.submit();
        return $customer_id.val();
    }

    $showMoreWaitingList.click(function() {
        var customer_id = get_customer_id();

        $.ajax({
            url:"<?=url('customer/genMoreWaitingList')?>",
            data: 'customer_id=' + customer_id,
            dataType: 'json',
            type:'post',
            beforeSend: function() {
                $showMoreWaitingList.attr('disabled', 'disabled');
            },
            success:function(res) {
                if (res.ack == 'success') {
                    refreshWaitingList(res.waitingList, true);
                } else {
                    alert(res.msg);
                }
            }
            ,
            complete:function() {
                $showMoreWaitingList.attr('disabled', '');
            }
        });
    });

    $refreshWaitingList.click(function() {
        var customer_id = get_customer_id();

        $.ajax({
            url:"<?=url('customer/waitingList')?>",
            data: 'customer_id=' + customer_id,
            dataType: 'json',
            type:'post',
            beforeSend: function() {
                $refreshWaitingList.attr('disabled', 'disabled');
            },
            success:function(res) {
                if (res.ack == 'success') {
                    refreshWaitingList(res.waitingList);
                } else {
                    alert(res.msg);
                }
            }
            ,
            complete:function() {
                $refreshWaitingList.attr('disabled', '');
            }
        });
    });

    function refreshWaitingList(waitingList, append) {
        var html = '';

        $.each(waitingList, function(index, waitingMail) {
            html += '<tr>' +
                    '<td>' + waitingMail.to + '</td>' +
                    '<td>' + waitingMail.subject + '</td>' +
                    '<td>' + waitingMail.send_date + ' ' + waitingMail.send_time + '</td>' +
                    '</tr>';
        });

        if (append) {
            $waitingListTable.find('tbody').append(html);
        } else {
            $waitingListTable.find('tbody').html(html);
        }
    }

    $('input[name=mail_plan_start_date]', $mailPlanCfgPanel).dateinput({
        format: 'yyyy-mm-dd',
        selectors:true
    });

    $mailAddressTable.find('tbody tr').each(function(index, row) {
        var mail_address_id = $(row).find('.mail_address_id').val();
        var address = $(row).find('.address').text();

        mailAddresses[mail_address_id] = address;
    });

    $('img.unbind', $mailAddressPlanTable).live('click', function() {
        var $srcEl = $(this);
        var $row = $srcEl.closest('tr');
        var mail_address_plan_id = $('input.mail_address_plan_id', $row).val();

        $.ajax({
            url:"<?=url('customer/unbindMailPlan')?>",
            data: 'mail_address_plan_id=' + mail_address_plan_id,
            dataType: 'json',
            type:'post',
            beforeSend: function() {
                $srcEl.attr('src', '<?=$_BASE_DIR?>img/icon/loading.gif');
            },
            success:function(res) {
                if (res.ack == 'success') {
                    $row.remove();
                } else {
                    alert(res.msg);
                }
            }
        });
    });

    $submitMailPlanCfg.click(function() {
        var data = $('#mailPlanCfgForm').serialize();
        $submitMailPlanCfg.oldVal = $submitMailPlanCfg.val();

        $.ajax({
            url:"<?=url('mail/cfgMailPlan')?>",
            data: data,
            dataType: 'json',
            type:'post',
            beforeSend: function() {
                $submitMailPlanCfg.val('提交中...').attr('disabled', "disabled");
            },
            success:function(res) {
                if (res.ack == 'success') {

                    var mail_address_plan_id = $('input[name=mail_address_plan_id]', $mailPlanCfgPanel).val();
                    var $row = $('input.mail_address_plan_id[value=' + mail_address_plan_id + ']', $mailAddressPlanTable).closest('tr');
                    var mail_plan_address_to = $('#mail_plan_address_to_id>option:selected').text();
                    var mail_plan_address_to_id = $('#mail_plan_address_to_id').val();
                    var mail_plan_status = $('input:checked[name=mail_plan_status]', $mailPlanCfgPanel).val();
                    if (mail_plan_status == 1) {
                        var mail_plan_status_text = '正常运行';
                    } else {
                        var mail_plan_status_text = '已暂停';
                    }
                    var mail_plan_start_date = $('input[name=mail_plan_start_date]', $mailPlanCfgPanel).val();
                    var mail_plan_next_tpl_index = $('input[name=mail_plan_next_tpl_index]', $mailPlanCfgPanel).val();

                    $('.mail_plan_address_to_id', $row).val(mail_plan_address_to_id);
                    $('.mail_plan_address_to', $row).html(mail_plan_address_to);
                    $('.mail_plan_status_text', $row).html(mail_plan_status_text);
                    $('.mail_plan_status', $row).val(mail_plan_status);
                    $('.mail_plan_start_date', $row).val(mail_plan_start_date);
                    $('.mail_plan_next_tpl_index', $row).val(mail_plan_next_tpl_index);

                } else {
                    alert(res.msg);
                }
            },
            complete:function() {
                $submitMailPlanCfg.val($submitMailPlanCfg.oldVal).attr('disabled', "");
            }
        });
    });

    $('img.cfg', $mailAddressPlanTable).live('click', function(e) {
        e.preventDefault(); //prevent default link action

        $(this).overlay({
            mask: {
                color: '#999',
                loadSpeed: 200,
                opacity: 0.9
            },
            load:true,// show the overlay immediate after initial
            closeOnClick:false,
            onBeforeLoad:function() {
                var $row = this.getTrigger().closest('tr');
                var mail_plan_name = $('.mail_plan_name', $row).text();
                var mail_plan_address_to_id = $('.mail_plan_address_to_id', $row).val();
                var mail_plan_status = $('.mail_plan_status', $row).val();
                var mail_plan_start_date = $('.mail_plan_start_date', $row).val();
                var mail_plan_next_tpl_index = $('.mail_plan_next_tpl_index', $row).val();
                var mail_address_plan_id = $('.mail_address_plan_id', $row).val();
                var optionsHtml = '';
                for (var mail_address_id in mailAddresses) {
                    optionsHtml += '<option value="' + mail_address_id + '">' + mailAddresses[mail_address_id] + '</option>';
                }

                $('.mail_plan_address_to_id', $mailPlanCfgPanel).html(optionsHtml);
                $('input[name=mail_address_plan_id]', $mailPlanCfgPanel).val(mail_address_plan_id);
                $('.mail_plan_name', $mailPlanCfgPanel).html(mail_plan_name);
                $('.mail_plan_address_to_id', $mailPlanCfgPanel).val(mail_plan_address_to_id);
                $('input[name=mail_plan_status][value=' + mail_plan_status + ']', $mailPlanCfgPanel).attr('checked', 'checked');

                // at the begining mail_plan_start_date and mail_plan_next_tpl_index is not working
                $('#mail_plan_status_detail').hide();
                $('input[name=mail_plan_start_date]', $mailPlanCfgPanel).attr('disabled', 'disabled');
                $('input[name=mail_plan_next_tpl_index]', $mailPlanCfgPanel).attr('disabled', 'disabled');

                $('input[name=mail_plan_start_date]', $mailPlanCfgPanel).val(mail_plan_start_date);
                $('input[name=mail_plan_next_tpl_index]', $mailPlanCfgPanel).val(mail_plan_next_tpl_index);
            }
        });

    });

    $('#mail_plan_status_2').change(function() {
        $('#mail_plan_status_detail').hide();
        $('input[name=mail_plan_start_date]', $mailPlanCfgPanel).attr('disabled', 'disabled');
        $('input[name=mail_plan_next_tpl_index]', $mailPlanCfgPanel).attr('disabled', 'disabled');
    });

    $('#mail_plan_status_1').change(function() {
        $('input[name=mail_plan_start_date]', $mailPlanCfgPanel).attr('disabled', '');
        $('input[name=mail_plan_next_tpl_index]', $mailPlanCfgPanel).attr('disabled', '');
        $('#mail_plan_status_detail').show();
    });

    $bindMailPlanTrg.click(function() {
        var customer_id = get_customer_id();
        var data = $mailPlanTable.closest('form').serialize() + '&customer_id=' + customer_id
        $bindMailPlanTrg.oldVal = $bindMailPlanTrg.val();

        $.ajax({
            url:"<?=url('customer/bindMailPlan')?>",
            data: data,
            dataType: 'json',
            type:'post',
            beforeSend: function() {
                $bindMailPlanTrg.val('提交中...').attr('disabled', "disabled");
            },
            success:function(res) {
                if (res.ack == 'success') {
                    appendMailPlans(res.newMailPlans);
                    $showMailPlanPanelTrg.overlay().close();
                } else {
                    alert(res.msg);
                }
            },
            complete:function() {
                $bindMailPlanTrg.val($bindMailPlanTrg.oldVal).attr('disabled', "");
            }
        });
    });

    function appendMailPlans(newMailPlans) {
        var html = '';

        $.each(newMailPlans, function(index, newMailPlan) {
            html += '<tr>' +
                    '<td class="mail_plan_name">' + newMailPlan.mail_plan_name + '</td>' +
                    '<td><?=Q::ini('appini/site/contactMail')?></td>' +
                    '<td>' +
                    '<span class="mail_plan_address_to">' + newMailPlan.mail_address + '</span>' +
                    '<input type="hidden" class="mail_plan_address_to_id" value="' + newMailPlan.mail_address_id + '">' +
                    '</td>' +
                    '<td>' +
                    '<span class="mail_plan_status_text">已暂停</span>' +
                    '<input type="hidden" class="mail_address_plan_id" value="' + newMailPlan.mail_address_plan_id + '">' +
                    '<input type="hidden" class="mail_plan_status" value="2">' +
                    '<input type="hidden" class="mail_plan_start_date" value="">' +
                    '<input type="hidden" class="mail_plan_next_tpl_num" value="1">' +
                    '</td>' +
                    '<td>' +
                    '<img src="<?=$_BASE_DIR?>img/icon/Configure.png" title="设置" class="cfg" rel="#mailPlanCfgPanel"/>' +
                    '<img src="<?=$_BASE_DIR?>img/icon/Delete.png" title="解除绑定" class="unbind" id="unbindMailPlan"/>' +
                    '</td>' +
                    '</tr>';
        });
        $mailAddressPlanTable.append(html);
    }

    $('#showMailPlanPanelTrg').overlay({
        mask: {
            color: '#999',
            loadSpeed: 200,
            opacity: 0.9
        },
        onBeforeLoad:function() {
            var optionsHtml = '';
            for (var mail_address_id in mailAddresses) {
                optionsHtml += '<option value="' + mail_address_id + '">' + mailAddresses[mail_address_id] + '</option>';
            }

            $('#bind_to_mail_address_id').html(optionsHtml);
        }
    });

    $(':radio', $mailAddressTable).live('click', function() {
        var $srcEl = $(this);
        var mail_address_id = $srcEl.val();
        var $resultPanel = $('<span class="warning">数据传输中...</span>');
        var customer_id = get_customer_id();

        $.ajax({
            url:"<?=url('customer/setDefaultMailAddress')?>",
            data: 'mail_address_id=' + mail_address_id + '&cid=' + customer_id,
            dataType:'json',
            type:'post',
            beforeSend: function() {
                $srcEl.closest('td').append($resultPanel);
            },
            success:function(res) {
                if (res.ack == 'success') {
                    $resultPanel.html('更改成功').removeClass('warning').addClass('success').fadeOut(5000);
                } else {
                    alert(res.msg);
                }
            }
        });
    });

    $('img.del', $mailAddressTable).live('click', function() {
        var $srcEl = $(this);
        var $row = $srcEl.closest('tr');
        var mail_address_id = $row.attr('mail_address_id');

        $.ajax({
            url:"<?=url('mail/del')?>",
            data: 'aid=' + mail_address_id,
            dataType:'json',
            type:'post',
            beforeSend: function() {
                $srcEl.attr('src', '<?=$_BASE_DIR?>img/icon/loading.gif');
            },
            success:function(res) {
                if (res.ack == 'success') {
                    $row.remove();
                    delete mailAddresses[mail_address_id];
                } else {
                    alert(res.msg);
                }
            }
        });
    });


    $country_id.change(function() {
        var offset = $(':selected', $country_id).attr('utc_offset');
        var html;

        offset = offset.split(',');

        if (offset.length > 1) {
            html = '<select id="utc_offset" name="utc_offset">';
            $.each(offset, function(index, value) {
                html += '<option value="' + value + '">' + value + '</option>';
            })
            html += '</select>';
        } else {
            html = '<input readonly name="utc_offset" id="utc_offset" value="' + offset[0] + '" />';
        }

        $('#utc_offset').closest('td').html(html);
    });

    $addProfessionBtn.overlay({
        mask: {
            color: '#999',
            loadSpeed: 200,
            opacity: 0.9
        },
        onLoad:function() {
            $newProfession.focus()
        }
    });

    $addMailAddressBtn.overlay({
        mask: {
            color: '#999',
            loadSpeed: 200,
            opacity: 0.9
        },
        onLoad:function() {
            $newMailAddress.val('').focus();
        }
    });

    $addProfessionForm.submit(function() {
        var newProfession = $newProfession.val();

        $.ajax({
            url:"<?=url('profession/add')?>",
            data: 'name=' + newProfession,
            dataType:'json',
            type:'post',
            beforeSend: function() {
                $addProfessionResult.html('processing...');
            },
            success:function(res) {
                if (res.ack == 'success') {
                    var newProfession = res.newProfession;
                    $addProfessionBtn.overlay().close();
                    var option = '<option value="' + newProfession.profession_id + '">' + newProfession.name + '</option>';
                    $profession_id.append(option);
                    $profession_id.val(newProfession.profession_id)
                } else {
                    alert(res.msg);
                }
            },
            complete:function() {
                $addProfessionResult.html('');
            }
        });

        return false; //cancel the submit action
    });

    $addMailAddressForm.submit(function() {
        var newMailAddress = $newMailAddress.val();
        var customer_id = get_customer_id();

        $.ajax({
            url:"<?=url('customer/addMailAddress')?>",
            data: 'cid=' + customer_id + '&mailAddress=' + newMailAddress,
            dataType:'json',
            type:'post',
            beforeSend: function() {
                $addMailAddressResult.html('processing...');
            },
            success:function(res) {
                if (res.ack == 'success') {
                    var newMailAddress = res.newMailAddress;
                    $addMailAddressBtn.overlay().close();

                    var row = '<tr mail_address_id="' + newMailAddress.mail_address_id + '">' +
                            '<td class="address">' + newMailAddress.address + '</td>' +
                            '<td><input type="radio" name="mail_address_id" value="' + newMailAddress.mail_address_id + '" />' +
                            '</td>' +
                            '<td><img src="<?=$_BASE_DIR?>img/icon/Delete.png" title="删除" class="del"/></td>' +
                            '</tr>';
                    $mailAddressTable.append(row);
                    mailAddresses[newMailAddress.mail_address_id] = newMailAddress.address;

                } else {
                    alert(res.msg);
                }
            },
            complete:function() {
                $addMailAddressResult.html('');
            }
        });

        return false; //cancel the submit action
    });


    $("#mainForm input:date").dateinput({
        format: 'yyyy-mm-dd',
        selectors: true,
        yearRange:[-100,1]
    });

    $("ul.tabs").tabs("div.panes > div");
    var api = $("ul.tabs").data("tabs");

    api.onClick(function(e, index) {
        if (index != 3) return;

        if ($waitingListTable.find('tbody').children().length != 0) return;

        $refreshWaitingList.click();
    });

})
        ;
</script>

<style type="text/css">
    .dataTable img {
        cursor: pointer
    }

    .overlay {
        background-color: #fff;
        display: none;
        width: 350px;
        padding: 15px;
        text-align: left;
        border: 2px solid #333;

        opacity: 0.8;
        -moz-border-radius: 6px;
        -webkit-border-radius: 6px;
        -moz-box-shadow: 0 0 50px #ccc;
        -webkit-box-shadow: 0 0 50px #ccc;
    }

    .overlay td {
        background: #ffffff
    }

    .overlay h2 {
        padding: 10px;
        border-bottom: 1px solid #333;
        font-size: 20px;
    }
</style>

<?php $this->_endblock('js'); ?>


<?php $this->_block('contents'); ?>

<? if (isset($errorMsg)): ?>
<div class="error"><?=$errorMsg?></div>
<? endif ?>



<ul class="tabs">
    <li><a href="#">基本资料</a></li>
    <? if ($_ctx->cid) { ?>
    <li><a href="#">邮箱地址</a></li>
    <li><a href="#">邮件计划</a></li>
    <li><a href="#">待发邮件列表</a></li>
    <li><a href="#">联系记录</a></li>
    <? } ?>
</ul>

<div class="panes">
    <div>
        <form name="mainForm" method="post" id="mainForm">
            <input type="hidden" id="customer_id" name="customer_id" value="<?=$_ctx['cid']?>"/>
            <table>
                <tr>
                    <td>国家</td>
                    <td><?=renderCountryId($customer->country_id)?></td>
                    <td>时区</td>
                    <td><?=renderUtcOffset($customer->utc_offset)?></td>
                </tr>
                <tr>
                    <td>编号</td>
                    <td><input name="customer_num" value="<?=$customer->customer_num?>"></td>
                </tr>
                <tr>
                    <td>全名</td>
                    <td><input name="full_name" value="<?=$customer->full_name?>"></td>
                    <td>昵称</td>
                    <td><input name="nick_name" value="<?=$customer->nick_name?>"></td>
                </tr>
                <tr>
                    <td>行业分类</td>
                    <td><?=Q::control('dropdownlist', 'profession_id', array('items' => Profession::items(), 'value' => $customer->profession_id, 'emptyText' => '--请选择--'))?>
                        <a id="addProfessionBtn" href="javascript:;" rel="#addProfessionPanel">增加行业</a></td>
                    <td>网站</td>
                    <td>
                        <input name="web_site" value="<?=$customer->web_site?>">
                        <? if ($customer->web_site) { ?>
                        <a target="_blank" href="<?=$customer->web_site()?>">打开网站</a>
                        <? } ?>
                    </td>
                </tr>
                <tr>
                    <td>客户等级</td>
                    <td><input name="grade" value="<?=$customer->grade?>"></td>
                    <td>生日</td>
                    <td><input type="date" name="birth_date" value="<?=$customer->birth_date?>"></td>
                </tr>
                <tr>
                    <td valign="top">备注</td>
                    <td colspan="3"><textarea rows="20" cols="100" name="remark"><?=$customer->remark?></textarea></td>
                </tr>
            </table>
            <input type="submit" value="提交资料" id="submitBaseData"/>
        </form>
    </div>
    <? if ($_ctx->cid) { ?>
    <div>
        <table class="dataTable" id="mailAddressTable">
            <thead>
            <tr>
                <th align="left">邮箱地址</th>
                <th align="left" width="120">默认邮箱</th>
                <th align="left">操作</th>
            </tr>
            </thead>
            <tbody>
                <? foreach ($customer->mailAddresses as $ma) { ?>
            <tr mail_address_id="<?=$ma->id()?>">
                <td class="address"><?=$ma->address?></td>
                <td><input type="radio" name="mail_address_id" class="mail_address_id"
                           value="<?=$ma->id()?>"<? if ($customer->default_mail_address_id == $ma->id()) echo 'checked' ?> />
                </td>
                <td><img src="<?=$_BASE_DIR?>img/icon/Delete.png" title="删除" class="del"/></td>
            </tr>
                <? } ?>
            </tbody>
        </table>
        <a id="addMailAddressBtn" href="javascript:;" rel="#addMailAddressPanel">增加邮箱地址</a>
    </div>
    <div>
        <table class="dataTable" id="mailAddressPlanTable">
            <tr>
                <th>计划名称</th>
                <th>发件邮箱</th>
                <th>收件邮箱</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            <? foreach ($customer->mailAddressPlans as $ap) { ?>
            <tr>
                <td class="mail_plan_name"><?=$ap->planName()?></td>
                <td><?=Q::ini('appini/site/contactMail')?></td>
                <td>
                    <span class="mail_plan_address_to"><?=$ap->address()?></span>
                    <input type="hidden" class="mail_plan_address_to_id" value="<?=$ap->mail_address_id?>">
                </td>
                <td>
                    <span class="mail_plan_status_text"><?=renderAddressMailStatus($ap->status)?></span>
                    <input type="hidden" class="mail_address_plan_id" value="<?=$ap->id()?>">
                    <input type="hidden" class="mail_plan_status" value="<?=$ap->status?>">
                    <input type="hidden" class="mail_plan_start_date" value="<?=$ap->start_date?>">
                    <input type="hidden" class="mail_plan_next_tpl_num" value="<?=$ap->next_tpl_num?>">
                </td>
                <td>
                    <img src="<?=$_BASE_DIR?>img/icon/Configure.png" title="设置" class="cfg"
                         rel="#mailPlanCfgPanel"/>
                    <img src="<?=$_BASE_DIR?>img/icon/Delete.png" title="解除绑定" class="unbind" id="unbindMailPlan"/>
                </td>
            </tr>
            <? } ?>
        </table>

        <input type="button" id="showMailPlanPanelTrg" value="添加邮件计划" rel="#mailPlanPanel"/>
    </div>
    <div>
        <table class="dataTable" id="waitingListTable">
            <thead>
            <tr>
                <th>收件邮箱</th>
                <th>主题</th>
                <th>预定发送时间</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
        <input type="button" value="刷新" id="refreshWaitingList">
        <input type="button" value="显示更多" id="showMoreWaitingList">
    </div>
    <div>Contact Record coming soon...</div>
    <? }//eo if($_ctx->cid) ?>
</div>

<div id="addProfessionPanel" class="overlay">
    <h2>增加行业</h2>

    <form id="addProfessionForm">
        行业名称
        <input id="newProfession">
        <br><br>
        <input type="submit" value="确定">
        <input type="button" value="返回" class="close">
    </form>


    <div id="addProfessionResult"></div>

</div>

<div id="addMailAddressPanel" class="overlay">
    <h2>增加邮箱地址</h2>

    <form id="addMailAddressForm">
        邮箱地址
        <input id="newMailAddress">
        <br><br>
        <input type="submit" value="确定">
        <input type="button" value="返回" class="close">
    </form>

    <div id="addMailAddressResult"></div>

</div>

<div id="mailPlanPanel" class="overlay">
    <h2>添加邮件计划</h2>

    <form>
        <table class="dataTable" id="mailPlanTable">
            <tr>
                <th width="20"></th>
                <th>计划名称</th>
            </tr>
            <? foreach ($mailPlans as $mp) { ?>
            <tr>
                <td><input type="checkbox" name="mail_plan_ids[]" value="<?=$mp->mail_plan_id?>"></td>
                <td><?=$mp->name?></td>
            </tr>
            <? } ?>
        </table>


        绑定到邮箱：<?=Q::control('dropdownlist', 'bind_to_mail_address_id', array('class' => 'bind_to_mail_address_id'))?>
    <br><br>
    </form>

    <input type="button" value="添加选中的邮件计划" id="bindMailPlanTrg">
    <input type="button" value="返回" class="close">
</div>

<div id="mailPlanCfgPanel" class="overlay">
    <h2>设置邮件计划[<span class="mail_plan_name"></span>]</h2>

    <form id="mailPlanCfgForm">
        <input name="mail_address_plan_id" type="hidden">
        <table class="dataTable">
            <tr>
                <td>发件邮箱</td>
                <td class="mail_address_from"><?=Q::ini('appini/site/contactMail')?></td>
            </tr>
            <tr>
                <td>收件邮箱</td>
                <td>
                    <?=Q::control('dropdownlist', 'mail_plan_address_to_id', array('class' => 'mail_plan_address_to_id'))?>
                </td>
            </tr>
            <tr>
                <td>状态</td>
                <td>
                    <input type="radio" name="mail_plan_status" value="2" id="mail_plan_status_2"> 暂停
                    <input type="radio" name="mail_plan_status" value="1" id="mail_plan_status_1"> 开始<br>

                    <div id="mail_plan_status_detail">
                        开始日期<input type="date" name="mail_plan_start_date"><br>
                        从第<input size="1" name="mail_plan_next_tpl_num">个模板开始
                    </div>
                </td>
            </tr>
        </table>
    </form>
    <br>
    <input type="button" value="确定" id="submitMailPlanCfg">
    <input type="button" value="返回" class="close">
</div>
<?php $this->_endblock('contents'); ?>
